package com.the_ring.chapter13.work;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

public class CollectWork extends Worker {

    private final static String TAG = "CollectWorker";
    private Data inputData; // 工作者的输入数据


    public CollectWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
        inputData = workerParams.getInputData();
    }

    @NonNull
    @Override
    public Result doWork() {
        String desc = String.format("请求参数包括：姓名=%s, 身高=%d, 体重=%f", inputData.getString("name"), inputData.getInt("height", 0), inputData.getDouble("weight", 0));
        Log.d(TAG, "doWork " + desc);
        // 这里填写描述的业务逻辑代码
        Data outputData = new Data.Builder()
                .putInt("resultCode", 0)
                .putString("resultDesc", "处理成功")
                .build();
        return Result.success(outputData);
    }
}
